/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Reportes;

import java.util.Vector;
import Model.Cliente;
import Servicio.Conexion;
import java.io.File;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Locale;
import jxl.CellReferenceHelper;
import jxl.CellView;
import jxl.HeaderFooter;
import jxl.Range;
import jxl.Workbook;
import jxl.WorkbookSettings;
import jxl.format.Alignment;
import jxl.format.Border;
import jxl.format.BorderLineStyle;
import jxl.format.Colour;
import jxl.format.Orientation;
import jxl.format.PageOrder;
import jxl.format.PageOrientation;
import jxl.format.PaperSize;
import jxl.format.ScriptStyle;
import jxl.format.UnderlineStyle;
import jxl.write.Blank;
import jxl.write.Boolean;
import jxl.write.DateFormat;
import jxl.write.DateFormats;
import jxl.write.DateTime;
import jxl.write.Formula;
import jxl.write.Label;
import jxl.write.Number;
import jxl.write.NumberFormat;
import jxl.write.NumberFormats;
import jxl.write.WritableCellFeatures;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableHyperlink;
import jxl.write.WritableImage;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;

/**
 *
 * @author usuario
 */
public abstract class ManejaExcel {
protected WritableCellFormat wrappedText;
protected WritableCellFormat arial10BoldFormat;
protected WritableWorkbook workbook;
protected String filename, param1,param2,opcion2;
protected int opcion1;
private Statement statement;
private Conexion con;


    public ManejaExcel( String name, String parametro1, String parametro2, int opc1, String opc2){
        try{
            param1=parametro1;
            param2=parametro2;
            opcion1=opc1;
            opcion2=opc2;
            WorkbookSettings ws = new WorkbookSettings();
            ws.setLocale(new Locale("en", "EN"));
            filename=name+".xls";
            workbook = Workbook.createWorkbook(new File(filename), ws);
            //formato texto
            wrappedText = new WritableCellFormat (WritableWorkbook.ARIAL_10_PT);
            wrappedText.setWrap(true);
            //formato titulos
            WritableFont arial10ptBold = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD);
            arial10BoldFormat = new WritableCellFormat(arial10ptBold);

      
        }catch(Exception e){e.printStackTrace();}
    }

    public void generaReporte(){
       try{    
       escribirInfo();
       statement.close();
       con.closeConection();
        workbook.write();
       workbook.close();
       }catch(Exception e){e.printStackTrace();}
    }
    
    protected abstract void escribirInfo();
    
    protected ResultSet  traeInfo(String consulta){
        con = Conexion.getInstance();
        ResultSet resultSet=null;
        con.setConection();
         try {
       statement = con.getConexion().createStatement();
       resultSet = statement.executeQuery(consulta);
       } catch (Exception e) {e.printStackTrace();  }
        
        
        return resultSet;
       
       
    }
    
    protected String where(){
        String val=" ";
        switch(opcion1){
             case 1: val=  " WHERE Iniciales_Congreso like '"+param1+"' and Fecha_Congreso ='"+param2+"' "; break;
             case 2: val=  " WHERE Fecha_Congreso between '"+param1+"' and '"+param2+"' "; break;
             case 3: val=  " WHERE Fecha between '"+param1+"' and '"+param2+"' "; break;
         }
        return val;
    }
}


